function fieldSportsFilter(field){
	var temp = ""+field;
	var low = temp.toLowerCase();
	var lower = new Array()
	
	for(var i=0;i<low.length;i++){
		if(low.charAt(i)=='á' || low.charAt(i)=='à' || low.charAt(i)=='â' || low.charAt(i)=='ã'){
			lower[i]='a';
		} else if(low.charAt(i)=='é' || low.charAt(i)=='è' || low.charAt(i)=='ê'){
			lower[i]='e';
		} else if(low.charAt(i)=='í' || low.charAt(i)=='ì' || low.charAt(i)=='î'){
			lower[i]='i';
		} else if(low.charAt(i)=='ó' || low.charAt(i)=='ò' || low.charAt(i)=='ô' || low.charAt(i)=='õ'){
			lower[i]='o';
		} else if(low.charAt(i)=='ú' || low.charAt(i)=='ù' || low.charAt(i)=='û'){
			lower[i]='u';
		} else if(low.charAt(i)=='ç'){
			lower[i]='c';
		} else{
			lower[i]=low.charAt(i);	
		}
	}

	var result="";
	for(var j=0;j<low.length;j++){
		result+=lower[j];
	}	

	return result;
};

function createTab(url){
	var one_Id = tabs.addTab("One");       
	_gel(one_Id).innerHTML = '<iframe src="'+url+'" height="50%" width="80%"></iframe>';
};

function searchSports(fieldSports){
	if (fieldSports.indexOf('futebol')!=-1){
		var soccer = 'Would not you buy these special priced soccer items?<br/>';
		soccer += '<a href="javascript:createTab(\'http://www.sportsauthority.com/product/index.jsp?productId=3050741&cp=3079740&sr=1&origkw=soccer&parentPage=category\');">';
		soccer += '<img src="http://monkeinstein.googlecode.com/svn/trunk/Sports/puttingpictures/soccer/ball.jpg"/>';
		soccer += '</a>';
		document.getElementById('soccer').innerHTML= soccer;
	}
	if (fieldSports.indexOf('natacao')!=-1){
		var swimming = 'Would not you buy these special priced swimming items?<br/>';
		swimming += '<a href="http://www.sportsauthority.com/product/index.jsp?productId=2210863&cp=&sr=1&origkw=swimming&kw=swimming&parentPage=search"';
		swimming += '<img src="http://monkeinstein.googlecode.com/svn/trunk/Sports/puttingpictures/swimming/kit.jpg"/>';
		swimming +='</a>';
		document.getElementById('swimming').innerHTML= swimming;
	}
	if (fieldSports.indexOf('volei')!=-1){
		var volley = 'Would not you buy these special priced volley items?<br/>';
		volley += '<a href="http://www.sportsauthority.com/product/index.jsp?productId=543460&cp=&sr=1&origkw=volley&kw=volley&parentPage=search">';
		volley += '<img src="http://monkeinstein.googlecode.com/svn/trunk/Sports/puttingpictures/volley/ball.jpg"/>';
		volley += '</a>';
		document.getElementById('volley').innerHTML= volley;
	}
};

function loadSports() {
  var params = {};
  params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [opensocial.Person.Field.SPORTS];
  var req = opensocial.newDataRequest();
  req.add(req.newFetchPersonRequest('VIEWER', params), 'viewer');
  req.send(onLoadSports);
};

function onLoadSports(data) {
	var viewer = data.get('viewer').getData();
	var fieldSports = viewer.getField(opensocial.Person.Field.SPORTS);
	document.getElementById('fieldSports').innerHTML = fieldSports;
	searchSports(fieldSportsFilter(fieldSports));
};

function init() {
   var main = tabs.addTab("menu");       
   loadSports();
};
